package com.fanbuchi.fukua.activity.base;

import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;

import com.fanbuchi.fukua.config.AppConfig;

import java.io.File;
import java.util.Random;

/**
 * Created by killerzhangsan on 2015/5/19.
 * @title 业务相关的封装
 */
public  class BaseActivity extends  SimpleActivity {
    public static final String mIdata= AppConfig.mIdata;
    public static final int requestCode=AppConfig.requestCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //can exec this funcation in here
        //setupViews();
    }

    /**Created by killerzhangsan on 2015/5/19.
     * @title 初始化控件内容
     */
    protected void setupViews(){

    }

    protected void bindData(){

    }

    protected  void call_dial(String phone){
        Intent intentTel = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
        startActivity(intentTel);
    }


    protected  void call(String phone){
        Intent intentTel = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phone));
        startActivity(intentTel);
    }

    protected  void visitWeb(String url){
        Uri uri = Uri.parse(url);
        Intent intentWeb = new Intent(Intent.ACTION_VIEW, uri);
        startActivity(intentWeb);
    }


    protected String getPicturePath(){
/*        final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !canRemoveSDCard()
                ? (getExternalCacheDir(context) == null ? context.getCacheDir().getPath() : getExternalCacheDir(context).getPath()) : context.getCacheDir().getPath();
        File file = new File(cachePath + File.separator + fileName);
        if (file.exists()) {
            file.delete();
        }
        return cachePath + File.separator + fileName;*/
        String path=Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator+new Random().nextLong()+".jpg";
        return path;
    }

    protected String getPath(Uri uri) {
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, proj, null, null, null);
        String path = null;
        if (cursor != null) {
            cursor.moveToFirst();
            path = cursor.getString(0);
            cursor.close();
        }
        return path;
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }


    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
